package com.ruoyi.web.controller.wb;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wb.domain.WbMaintainCompanyUser;
import com.ruoyi.wb.dto.WbMaintainCompanyUserAddDto;
import com.ruoyi.wb.dto.WbMaintainCompanyUserPutDto;
import com.ruoyi.wb.service.IWbMaintainCompanyUserService;
import com.ruoyi.wb.vo.WbMaintainCompanyUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 维保公司 用户 关联Controller
 * 
 * @author ruoyi
 * @date 2024-10-28
 */
@RestController
@Api(tags="维保公司信息管理")
@RequestMapping("/wb/WbMaintainCompanyUser")
public class WbMaintainCompanyUserController extends BaseController
{
    @Autowired
    private IWbMaintainCompanyUserService wbMaintainCompanyUserService;

    /**
     * 查询维保公司 用户 关联列表
     */
    @GetMapping("/list")
    @ApiOperation("查询维保公司和用户关联表")
    public TableDataInfo list(WbMaintainCompanyUser wbMaintainCompanyUser)
    {
        List<WbMaintainCompanyUserVo> list = wbMaintainCompanyUserService.selectWbMaintainCompanyUserList(wbMaintainCompanyUser);
        return getDataTable(list);
    }

    @GetMapping("/listWbMaster")
    @ApiOperation("查询维保师傅")
    public TableDataInfo listWbMaster()
    {
        List<WbMaintainCompanyUserVo> list = wbMaintainCompanyUserService.listWbMaster();
        return getDataTable(list);
    }

    /**
     * 导出维保公司 用户 关联列表
     */
    @Log(title = "维保公司 用户 关联", businessType = BusinessType.EXPORT)
    @ApiOperation("导出维保公司 用户 关联列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, WbMaintainCompanyUser wbMaintainCompanyUser)
    {
        List<WbMaintainCompanyUser> list = BeanUtil.copyToList(wbMaintainCompanyUserService.selectWbMaintainCompanyUserList(wbMaintainCompanyUser),WbMaintainCompanyUser.class);
        ExcelUtil<WbMaintainCompanyUser> util = new ExcelUtil<WbMaintainCompanyUser>(WbMaintainCompanyUser.class);
        util.exportExcel(response, list, "维保公司 用户 关联数据");
    }

    /**
     * 获取维保公司 用户 关联详细信息
     */
    @ApiOperation("获取维保公司 用户 关联详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wbMaintainCompanyUserService.selectWbMaintainCompanyUserById(id));
    }

    /**
     * 新增维保公司 用户 关联
     */
    @ApiOperation("新增维保公司 用户 关联")
    @Log(title = "维保公司 用户 关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WbMaintainCompanyUserAddDto wbMaintainCompanyUserAddDto)
    {
        return toAjax(wbMaintainCompanyUserService.insertWbMaintainCompanyUser(wbMaintainCompanyUserAddDto));
    }

    /**
     * 修改维保公司 用户 关联
     */
    @ApiOperation("修改维保公司 用户 关联")
    @Log(title = "维保公司 用户 关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WbMaintainCompanyUserPutDto wbMaintainCompanyUserPutDto)
    {

        return toAjax(wbMaintainCompanyUserService.updateWbMaintainCompanyUser(wbMaintainCompanyUserPutDto));
    }


    /**
     * 修改员工为离职
     * @return
     */
    @ApiOperation("修改员工为离职")
    @Log(title = "修改员工为离职", businessType = BusinessType.UPDATE)
    @PutMapping("/dimission")
    public AjaxResult dimission(@RequestParam Long userId)
    {
        return toAjax(wbMaintainCompanyUserService.dimission(userId));
    }




    /**
     * 删除维保公司 用户 关联
     */
    @ApiOperation("删除维保公司 用户 关联")
    @Log(title = "维保公司 用户 关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wbMaintainCompanyUserService.deleteWbMaintainCompanyUserByIds(ids));
    }



}
